
#ifndef _CAMERA_H_
#define _CAMERA_H_


#include "config.h"
#include "d3dheaders.h"
#include "video/Frustum.h"

namespace KEngine
{
	class Device;
	class SceneManager;
	class Ray;
	class _KExport Camera : public Frustum
	{
	public:
		Camera();
		virtual ~Camera();

		void setDevice(Device* dev){_device = dev;}
		Device* getDevice() const{return _device;}
		void setSceneManager(SceneManager* mgr){_sceneMgr=mgr;}
		SceneManager* getSceneManager(){return _sceneMgr;}

		void walk(float unit);
		void strafe(float unit);
		void fly(float unit);

		void roll(float angle);
		void yaw(float angle);
		void pitch(float angle);

		void setPosition(const D3DXVECTOR3& pos);
		void setFixedYawAxis(bool fixed);

		void lookAt(const D3DXVECTOR3& targetPoint);
		void setDirection(const D3DXVECTOR3& vec);

		const D3DXVECTOR3& getDirection() const;
		const D3DXVECTOR3& getUp() const;

		const D3DXQUATERNION& getDerivedOrientation();
		const D3DXVECTOR3& getDerivedPosition();

		const D3DXQUATERNION& getRealOrientation();
		const D3DXVECTOR3& getRealPosition();

		Ray getCameraToViewportRay(float screenx, float screeny);
	protected:
		bool isViewOutOfDate();
		void calcViewOrientation();

		const D3DXVECTOR3& getPositionForViewUpdate() const;
		const D3DXQUATERNION& getOrientationForViewUpdate() const;
	

		Device* _device;
		SceneManager* _sceneMgr;

		D3DXVECTOR3			mRight;
		D3DXVECTOR3			mUp;
		D3DXVECTOR3			mLook;
		D3DXVECTOR3			mPosition;

		bool				mYawFixed;

		D3DXQUATERNION		mOrientation;
		D3DXQUATERNION		mDerivedOrientation;
		D3DXVECTOR3			mDerivedPosition;
		D3DXQUATERNION		mRealOrientation;
		D3DXVECTOR3			mRealPosition;
	};
	
};

#endif

